const BASE_URL = "https://admin.lykangshu.top"
// 封装请求方法
// https://admin.lykangshu.top  服务器地址
//https://admin.lykangshu.top/api/common/upload //图片上传地址
const token = uni.getStorageSync('token');

function request(url, method, data) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			method: method || 'POST',
			data: data,
			header: {
				'Content-Type': 'application/json', // 设置请求头
				"token": "f08148c2-beea-4404-836e-f427da646ebf",
				// "token": token || "f08148c2-beea-4404-836e-f427da646ebf",
			},
			success: (res) => {
				if (res.data.code == 1) {
					resolve(res);
				} else if (res.data.code == 401) {
					uni.showLoading({
						title: "跳转登录中"
					})
					setTimeout(() => {
						uni.hideLoading()
						uni.redirectTo({
							url: '/pages/login/login'
						})
					}, 2000)
				} else {
					reject(res)
				}
			},
			fail: (err) => {
				reject(err);
				uni.$u.toast("请求错误")
			},
		});
	});
}
export default request;